﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

public class ExitStatement : Statement
{
    private readonly SyntaxToken _exitKeywordToken;
    private SyntaxToken? _procedureKeywordToken;

    internal ExitStatement(SyntaxToken exitKeyword, SyntaxToken? procedureKeyword, SyntaxNode? parent) :
        base(SyntaxKinds.ExitStatement, parent)
    {
        SetChildField(ref _exitKeywordToken, exitKeyword);
        SetChildNullableField(ref _procedureKeywordToken, SyntaxToken.IsNullOrEmpty, procedureKeyword);
    }


    public SyntaxToken ExitKeywordToken => _exitKeywordToken;

    public SyntaxToken? ProcedureKeywordToken => _procedureKeywordToken;

    public ExitStatement Update(SyntaxToken procedureKeywordToken)
    {
        SetChildNullableField(ref _procedureKeywordToken, SyntaxToken.IsNullOrEmpty, procedureKeywordToken);
        return this;
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, ExitKeywordToken, ProcedureKeywordToken);
    }
}


public static partial class NodeFactory
{
    public static ExitStatement CreateExitStatement(SyntaxNode? parent, SyntaxToken exitKeyword,
        SyntaxToken? procedureKeyword)
    {
        Debug.Assert(exitKeyword.IsNode(SyntaxKinds.ExitKeywordToken));
        return new ExitStatement(exitKeyword, procedureKeyword, parent);
    }
}